package com.guoxue.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.guoxue.dao.IGiftListDao;
import com.guoxue.model.GiftList;
import com.guoxue.model.GiveAwayGiftList;
@Repository
public class GiftListDaoImpl  extends BaseDaoImpl<GiftList> implements IGiftListDao{

	@Override
	public List<GiftList> getGiftList(Integer giveUid,Integer tapesId) {
		return GiftListObjList("SELECT g.giveUid,sum(g.total) AS totalNumber,p.propIcon,p.propName FROM GiveAwayRecordVo g , PropertyConfigVo p where  g.goodsId = p.propId and g.giveUid = ? and g.tapesId = ? and g.sysflag=0 group by g.giveUid,goodsId order by totalNumber DESC", new Object[] {giveUid,tapesId});
	}

	@Override
	public GiftList getGift(Integer giveUid, Integer tapesId) {
		return GiftListFirstObj("SELECT g.giveUid,sum(g.total) AS totalNumber,p.propIcon,p.propName FROM GiveAwayRecordVo g , PropertyConfigVo p where  g.goodsId = p.propId and g.giveUid = ? and g.tapesId = ? and g.sysflag=0 group by g.giveUid,goodsId order by g.popularityValue DESC",new Object[] {giveUid,tapesId});
	}

	@Override
	public List<GiveAwayGiftList> getGiveAwayGiftList(Integer uid, Integer tapesId, Integer start, Integer total) {
		return GiveAwayGiftListObjList("SELECT g.giveUid,sum(g.popularityValue) AS totalPopularityValue ,u.nickName,u.imgUrl FROM GiveAwayRecordVo g , UserVo u where u.id = g.giveUid  and g.uid = ? and g.tapesId = ? and g.sysflag=0 group by giveUid order by totalPopularityValue DESC",new Object[] {uid,tapesId},start,total);
	}

	@Override
	public GiveAwayGiftList getGiveAwayGift(Integer uid, Integer tapesId) {
		return GiveAwayGiftListObj("SELECT g.giveUid,sum(g.popularityValue) AS totalPopularityValue ,u.nickName,u.imgUrl FROM GiveAwayRecordVo g , UserVo u where u.id = g.giveUid  and g.giveUid = ? and g.tapesId = ? and g.sysflag=0 group by giveUid order by totalPopularityValue DESC",new Object[] {uid,tapesId});
	}

	@Override
	public List<GiveAwayGiftList> getGiveAwayGiftList(Integer userId, Integer tapesId, Integer start, Integer total,
			String date) {
		return GiveAwayGiftListObjList("SELECT g.giveUid,sum(g.popularityValue) AS totalPopularityValue ,u.nickName,u.imgUrl FROM GiveAwayRecordVo g , UserVo u where u.id = g.giveUid  and g.uid = ? and g.tapesId = ? and g.sysflag=0 and g.giveTime <= ? group by giveUid order by totalPopularityValue DESC",new Object[] {userId,tapesId,date},start,total);
	}

}
